package com.fourth.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fourth.dao.UBbusinessDao;
import com.fourth.dao.UBorderDao;
import com.fourth.service.UBorderService;
import com.fourth.vo.GnameAndSendVo;
import com.fourth.vo.OrderVo;
import com.ljx.entity.BusinessInfo;
import com.ljx.entity.Order;
import com.ljx.security.util.WebUtils;
import com.ljx.utils.JwtUtil;
import com.ljx.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author LJX
 * @Description: TODO
 * @Date: 2023/3/7 16:00
 * @Version 1.0
 */
@Service
public class UBorderServiceImpl extends ServiceImpl<UBorderDao, Order> implements UBorderService {
	@Autowired(required = false)
	private UBorderDao uBorderDao;

	@Autowired(required = false)
	private UBbusinessDao uBbusinessDao;

	@Override
	public Result selectOrderAllByBid(Integer currentPage,Integer pageSize, GnameAndSendVo gnameAndSendVo) {
		Page<OrderVo> page = new Page<>(currentPage,pageSize);
		HttpServletRequest request = WebUtils.getRequest();
		String token = request.getHeader("token");
		Map<String, Object> map = JwtUtil.getTokenChaim(token);
		String username = (String) map.get("username");
		BusinessInfo businessInfo = uBbusinessDao.selectBusinessBytelephone(username);

		Page<OrderVo>  orderVos = uBorderDao.selectOrderAllByBid(page,businessInfo.getId(),gnameAndSendVo);
		for (OrderVo record : orderVos.getRecords()) {
			List<OrderVo> orderVos1 = uBorderDao.selectOrderByCode(record.getCode(),businessInfo.getId());
			record.setOrders(orderVos1);
		}
		if(orderVos!=null){
			return new Result(2000,"订单数据查询成功",orderVos);
		}
		return new Result(2000,"订单数据查询失败");

	}
}
